package map07;

import java.util.HashMap;

/*
集合套嵌：集合套集合
ArrayList<ArrayList>
ArrayList<HashSet>
HashMap<ArrayList,HashMap>
Map套Map
需求：
   一班
      1001 张三
      1002 李四
      1003 王五

   二班
      2003 无忌
      2005 乔峰
      2007 虚竹

  嵌套集合构造数据从内向外构建
  嵌套集遍历要从外向内遍历
 */
public class HashMapDemo01 {
    public static void main(String[] args) {
        //1.构建套嵌集合以及填充数据
        HashMap<String, String> students1 = new HashMap<>();
        students1.put("1001", "张三");
        students1.put("1002", "李四");
        students1.put("1003", "王五");

        HashMap<String, String> students2 = new HashMap<>();
        students2.put("2003", "无忌");
        students2.put("2004", "乔峰");
        students2.put("2005", "虚竹");

        //2.构建外层的HashMap<String,HashMap<String,String>>
        HashMap<String, HashMap<String, String>> classRoom = new HashMap<>();
        classRoom.put("一班", students1);
        classRoom.put("二班", students2);

        //2.遍历集合
        for (String roodName : classRoom.keySet()) {//遍历最外层集合
            HashMap<String, String> hm = classRoom.get(roodName);//根据当前遍历的key取出对应的value，这个value又是一个HashMap
            for (String sno : hm.keySet()) {
                System.out.println(roodName+" "+sno + " " + hm.get(sno));
            }

        }
    }
}
